<template>
  <div>
    <div
        :style='{"width":"100%","padding":"0px 7%","margin":"0px auto 10px","borderRadius":"0px","background":"#99cc99","height":"40px"}'
        class="breadcrumb-preview">
      <el-breadcrumb :separator="'Ξ'" :style='{"fontSize":"14px","lineHeight":"40px"}'>
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item v-for="(item, index) in breadcrumbItem" :key="index">{{ item.name }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="detail-preview"
         :style='{"width":"100%","padding":"10px 0 20px","margin":"70px auto 0","position":"relative"}'>
      <div class="attr"
           :style='{"padding":"0","position":"relative","flexWrap":"wrap","background":"none","justifyContent":"space-between","display":"flex"}'>
        <el-carousel :style='{"width":"100%","padding":"0","margin":"0px 7%","height":"400px"}' trigger="click"
                     indicator-position="inside" arrow="always" type="card" direction="horizontal" height="400px"
                     autoplay="true" interval="6000" loop="true">
          <el-carousel-item :style='{"borderRadius":"10px","width":"50%","height":"100%"}' v-for="item in detailBanner"
                            :key="item.id">
            <el-image :style='{"width":"100%","objectFit":"cover","borderRadius":"10px","height":"100%"}'
                      v-if="item.substr(0,4)=='http'" :src="item" fit="cover" class="image"></el-image>
            <el-image :style='{"width":"100%","objectFit":"cover","borderRadius":"10px","height":"100%"}' v-else
                      :src="baseUrl + item" fit="cover" class="image"></el-image>
          </el-carousel-item>
        </el-carousel>


        <div class="info"
             :style='{"minHeight":"500px","width":"100%","padding":"120px 7% 120px","margin":"0","background":"url(http://codegen.caihongy.cn/20230109/138a4d606eae4a168810cef229969885.png) no-repeat center top,url(http://codegen.caihongy.cn/20230109/b95aeae1c1294f398aefb7c6cd5b16de.png) no-repeat center top,url(http://codegen.caihongy.cn/20230109/5ffc803e6682418eb7f0b09a98e35527.png) no-repeat center bottom,#99CC99","order":"1"}'>
          <div class="item"
               :style='{"padding":"10px 20px 10px 50px","boxShadow":"0 3px 0 #ebdcc6","margin":"0 0 10px 0","alignItems":"center","background":"none","display":"flex","justifyContent":"space-between"}'>
            <div :style='{"padding":"0 30px","fontSize":"18px","color":"#cc8c2f","fontWeight":"600"}'>
              {{ detail.bisaimingcheng }}
            </div>
          </div>

          <div class="item"
               :style='{"padding":"10px","boxShadow":"0 2px 0 #ebdcc6","margin":"0 0 10px 0","justifyContent":"spaceBetween","display":"flex"}'>
            <div class="lable"
                 :style='{"padding":"0 10px","color":"#cc8c2f","textAlign":"right","width":"auto","fontSize":"16px","lineHeight":"40px","minWidth":"150px","height":"40px"}'>
              比赛时间
            </div>
            <div :style='{"width":"498px","padding":"8px 10px 0","fontSize":"14px","lineHeight":"24px","color":"#666"}'>
              {{ detail.bisaishijian }}
            </div>
          </div>
          <div class="item"
               :style='{"padding":"10px","boxShadow":"0 2px 0 #ebdcc6","margin":"0 0 10px 0","justifyContent":"spaceBetween","display":"flex"}'>
            <div class="lable"
                 :style='{"padding":"0 10px","color":"#cc8c2f","textAlign":"right","width":"auto","fontSize":"16px","lineHeight":"40px","minWidth":"150px","height":"40px"}'>
              主队
            </div>
            <div :style='{"width":"498px","padding":"8px 10px 0","fontSize":"14px","lineHeight":"24px","color":"#666"}'>
              {{ detail.zhudui }}
            </div>
          </div>
          <div class="item"
               :style='{"padding":"10px","boxShadow":"0 2px 0 #ebdcc6","margin":"0 0 10px 0","justifyContent":"spaceBetween","display":"flex"}'>
            <div class="lable"
                 :style='{"padding":"0 10px","color":"#cc8c2f","textAlign":"right","width":"auto","fontSize":"16px","lineHeight":"40px","minWidth":"150px","height":"40px"}'>
              比方
            </div>
            <div :style='{"width":"498px","padding":"8px 10px 0","fontSize":"14px","lineHeight":"24px","color":"#666"}'>
              {{ detail.bifang }}
            </div>
          </div>
          <div class="item"
               :style='{"padding":"10px","boxShadow":"0 2px 0 #ebdcc6","margin":"0 0 10px 0","justifyContent":"spaceBetween","display":"flex"}'>
            <div class="lable"
                 :style='{"padding":"0 10px","color":"#cc8c2f","textAlign":"right","width":"auto","fontSize":"16px","lineHeight":"40px","minWidth":"150px","height":"40px"}'>
              发布时间
            </div>
            <div :style='{"width":"498px","padding":"8px 10px 0","fontSize":"14px","lineHeight":"24px","color":"#666"}'>
              {{ detail.fabushijian }}
            </div>
          </div>
          <div class="btn" :style='{"padding":"10px 0","flexWrap":"wrap","display":"flex"}'>
          </div>
        </div>

      </div>


      <el-tabs class="detail"
               :style='{"border":"0px solid #DCDFE6","width":"100%","boxShadow":"0 1px 6px 0 rgba(0, 0, 0, .1)","padding":"0 7%","fontSize":"16px","background":"#fff"}'
               v-model="activeName" type="border-card">
        <el-tab-pane label="比赛结果" name="first">
          <div v-html="detail.bisaijieguo"></div>
        </el-tab-pane>
        <el-tab-pane label="评论" name="second">
          <el-form class="add comment"
                   :style='{"width":"100%","boxShadow":"0 0px 0px 0 rgba(0, 0, 0, .1)","padding":"15px","margin":"0 0 20px"}'
                   :model="form" :rules="rules" ref="form">
            <el-form-item class="item" :style='{"width":"100%","display":"flex","height":"auto"}' label="评论"
                          prop="content">
              <el-input type="textarea" :rows="5" v-model="form.content" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item class="btn"
                          :style='{"width":"75%","padding":"0 0 0 80px","margin":"10px 0 0","textAlign":"right","height":"auto"}'>
              <el-button
                  :style='{"border":"0","cursor":"pointer","padding":"0","margin":"0 20px 0 0","outline":"none","color":"rgba(255, 255, 255, 1)","borderRadius":"4px","background":"#ff9966","width":"128px","lineHeight":"40px","fontSize":"14px","height":"40px"}'
                  type="primary" @click="submitForm('form')">立即提交
              </el-button>
              <el-button
                  :style='{"border":"0","cursor":"pointer","padding":"0","margin":"0 20px 0 0","outline":"none","color":"rgba(255, 255, 255, 1)","borderRadius":"4px","background":"#1e8892","width":"128px","lineHeight":"40px","fontSize":"14px","height":"40px"}'
                  @click="resetForm('form')">重置
              </el-button>
            </el-form-item>
          </el-form>

          <div v-if="infoList.length" :style='{"boxShadow":"0 1px 6px 0 rgba(0, 0, 0, .1)","padding":"15px"}'
               class="comment">
            <div
                :style='{"padding":"8px 0","margin":"0 0 20px","borderColor":"#999","alignItems":"center","borderWidth":"0 0 1px 0","width":"100%","borderStyle":"solid","height":"auto"}'
                v-for="item in infoList" :key="item.id">
              <div class="user" :style='{"width":"100%","alignItems":"center","display":"flex","height":"auto"}'>
                <el-image v-if="item.avatarurl"
                          :style='{"width":"40px","margin":"0 10px 0 0","borderRadius":"100%","objectFit":"cover","height":"40px"}'
                          :size="50" :src="baseUrl + item.avatarurl"></el-image>
                <el-image v-if="!item.avatarurl"
                          :style='{"width":"40px","margin":"0 10px 0 0","borderRadius":"100%","objectFit":"cover","height":"40px"}'
                          :size="50" :src="require('@/assets/touxiang.png')"></el-image>
                <div :style='{"color":"#333","fontSize":"16px"}' class="name">{{ item.nickname }}</div>
              </div>
              <div
                  :style='{"padding":"8px","margin":"10px 0px 0px","lineHeight":"30px","fontSize":"14px","color":"#333","borderRadius":"4px"}'
                  class="content-block-ask">
                {{ item.content }}
              </div>
              <div
                  :style='{"padding":"8px","margin":"10px 0px 0px","lineHeight":"30px","fontSize":"14px","color":"#333","borderRadius":"4px"}'
                  class="content-block-reply" v-if="item.reply">
                回复：{{ item.reply }}
              </div>
            </div>
          </div>

          <el-pagination
              background
              class="pagination"
              :pager-count="7"
              :page-size="pageSize"
              :page-sizes="pageSizes"
              prev-text="<"
              next-text=">"
              :hide-on-single-page="true"
              :layout='["total","prev","pager","next","sizes","jumper"].join()'
              :total="total"
              :style='{"padding":"0","margin":"10px auto","whiteSpace":"nowrap","color":"#333","textAlign":"center","width":"100%","fontWeight":"500"}'
              @current-change="curChange"
              @prev-click="prevClick"
              @next-click="nextClick"
          ></el-pagination>
        </el-tab-pane>

      </el-tabs>
    </div>
  </div>
</template>

<script>
import CountDown from '@/components/CountDown';

export default {
  //数据集合
  data() {
    return {
      tablename: 'bisaijieguo',
      baseUrl: '',
      breadcrumbItem: [
        {
          name: '详情信息'
        }
      ],
      title: '',
      detailBanner: [],
      endTime: 0,
      detail: {},
      activeName: 'first',
      form: {
        content: '',
        userid: localStorage.getItem('userid'),
        nickname: localStorage.getItem('username'),
        avatarurl: '',
      },
      infoList: [],
      total: 1,
      pageSize: 5,
      pageSizes: [10, 20, 30, 50],
      totalPage: 1,
      rules: {
        content: [
          {required: true, message: '请输入内容', trigger: 'blur'}
        ]
      },
      buynumber: 1,
    }
  },
  created() {
    this.init();
  },
  //方法集合
  methods: {
    init() {
      this.baseUrl = this.$config.baseUrl;
      if (this.$route.query.detailObj) {
        this.detail = JSON.parse(this.$route.query.detailObj);
      }
      this.$http.get(this.tablename + '/detail/' + this.detail.id, {}).then(res => {
        if (res.data.code == 0) {
          this.detail = res.data.data;
          this.title = this.detail.bisaimingcheng;
          this.detailBanner = this.detail.fengmiantupian ? this.detail.fengmiantupian.split(",") : [];
          this.$forceUpdate();
        }
      });

      this.getDiscussList(1);

    },
    curChange(page) {
      this.getDiscussList(page);
    },
    prevClick(page) {
      this.getDiscussList(page);
    },
    nextClick(page) {
      this.getDiscussList(page);
    },
    // 下载
    download(file) {
      if (!file) {
        this.$message({
          type: 'error',
          message: '文件不存在',
          duration: 1500,
        });
        return;
      }
      window.open(this.baseUrl + file)
    },
    getDiscussList(page) {
      this.$http.get('discussbisaijieguo/list', {
        params: {
          page,
          limit: this.pageSize,
          refid: this.detail.id
        }
      }).then(res => {
        if (res.data.code == 0) {
          this.infoList = res.data.data.list;
          this.total = res.data.data.total;
          this.pageSize = res.data.data.pageSize;
          this.pageSizes = [this.pageSize, this.pageSize * 2, this.pageSize * 3, this.pageSize * 5];
          this.totalPage = res.data.data.totalPage;
        }
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.form.refid = this.detail.id;
          this.form.avatarurl = localStorage.getItem('headportrait') ? localStorage.getItem('headportrait') : '';
          this.$http.post('discussbisaijieguo/add', this.form).then(res => {
            if (res.data.code == 0) {
              this.form.content = '';
              this.getDiscussList(1);
              this.$message({
                type: 'success',
                message: '评论成功!',
                duration: 1500,
              });
            }
          });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },


  },
  components: {
    CountDown
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.detail-preview {

  .attr {
    .el-carousel ::v-deep .el-carousel__indicator button {
      width: 0;
      height: 0;
      display: none;
    }

    .el-input-number__decrease:hover:not(.is-disabled) ~ .el-input .el-input__inner:not(.is-disabled), .el-input-number__increase:hover:not(.is-disabled) ~ .el-input .el-input__inner:not(.is-disabled) {
      border-color: none;
    }
  }

  .detail {
    & ::v-deep .el-tabs__header .el-tabs__nav-wrap {
      margin-bottom: 0;
    }

    & .add .el-textarea {
      width: auto;
    }
  }
}

.attr .el-carousel ::v-deep .el-carousel__container .el-carousel__arrow--left {
  width: 36px;
  font-size: 12px;
  height: 36px;
}

.attr .el-carousel ::v-deep .el-carousel__container .el-carousel__arrow--left:hover {
  background: red;
}

.attr .el-carousel ::v-deep .el-carousel__container .el-carousel__arrow--right {
  width: 36px;
  font-size: 12px;
  height: 36px;
}

.attr .el-carousel ::v-deep .el-carousel__container .el-carousel__arrow--right:hover {
  background: red;
}

.attr .el-carousel ::v-deep .el-carousel__indicators {
  padding: 0;
  margin: 0 0 10px;
  z-index: 2;
  position: absolute;
  list-style: none;
}

.attr .el-carousel ::v-deep .el-carousel__indicators li {
  border-radius: 10px;
  padding: 0;
  margin: 0 4px;
  background: #fff;
  display: inline-block;
  width: 12px;
  opacity: 0.4;
  transition: 0.3s;
  height: 12px;
}

.attr .el-carousel ::v-deep .el-carousel__indicators li:hover {
  padding: 0;
  margin: 0 4px;
  background: #fff;
  display: inline-block;
  width: 24px;
  opacity: 0.7;
  height: 12px;
}

.attr .el-carousel ::v-deep .el-carousel__indicators li.is-active {
  padding: 0;
  margin: 0 4px;
  background: #fff;
  display: inline-block;
  width: 24px;
  opacity: 1;
  height: 12px;
}

.attr .el-input-number ::v-deep .el-input-number__decrease {
  cursor: pointer;
  z-index: 1;
  display: flex;
  border-color: #DCDFE6;
  border-radius: 4px 0 0 4px;
  top: 1px;
  left: 1px;
  background: #f5f5f5;
  width: 40px;
  justify-content: center;
  border-width: 0 1px 0 0;
  align-items: center;
  position: absolute;
  border-style: solid;
  text-align: center;
  height: 38px;
}

.attr .el-input-number ::v-deep .el-input-number__decrease i {
  color: #666;
  font-size: 14px;
}

.attr .el-input-number ::v-deep .el-input-number__increase {
  cursor: pointer;
  z-index: 1;
  display: flex;
  border-color: #DCDFE6;
  right: 1px;
  border-radius: 0 4px 4px 0;
  top: 1px;
  background: #f5f5f5;
  width: 40px;
  justify-content: center;
  border-width: 0 0 0 1px;
  align-items: center;
  position: absolute;
  border-style: solid;
  text-align: center;
  height: 38px;
}

.attr .el-input-number ::v-deep .el-input-number__increase i {
  color: #666;
  font-size: 14px;
}

.attr .el-input-number ::v-deep .el-input .el-input__inner {
  border: 1px solid #DCDFE6;
  border-radius: 4px;
  padding: 0 40px;
  outline: none;
  color: #666;
  background: #FFF;
  display: inline-block;
  width: 100%;
  font-size: 14px;
  line-height: 40px;
  text-align: center;
  height: 40px;
}

.detail-preview .detail.el-tabs ::v-deep .el-tabs__header {
  margin: 0;
  background: #fff;
  border-color: #E4E7ED;
  border-width: 0 0 1px 0;
  border-style: solid;
  height: 50px;
}

.detail-preview .detail.el-tabs ::v-deep .el-tabs__header .el-tabs__item {
  border: 0;
  padding: 0 20px;
  margin: 0 5px;
  color: #fff;
  background: #cca161;
  font-weight: 500;
  display: inline-block;
  font-size: 14px;
  line-height: 40px;
  position: relative;
  list-style: none;
  height: 40px;
}

.detail-preview .detail.el-tabs ::v-deep .el-tabs__header .el-tabs__item:hover {
  border: 0;
  margin: 0 5px;
  color: #fff;
  background: #1e8892;
}

.detail-preview .detail.el-tabs ::v-deep .el-tabs__header .el-tabs__item.is-active {
  border: 0;
  margin: 0 5px;
  color: #fff;
  background: #1e8892;
}

.detail-preview .detail.el-tabs ::v-deep .el-tabs__content {
  padding: 15px;
}

.detail-preview .detail.el-tabs .add ::v-deep .el-form-item__label {
  padding: 0 10px 0 0;
  color: #666;
  width: 80px;
  font-size: 14px;
  line-height: 40px;
  text-align: right;
}

.detail-preview .detail.el-tabs .add ::v-deep .el-textarea__inner {
  border: 1px solid #ddd;
  border-radius: 0;
  padding: 15px;
  box-shadow: inset 0px 0px 0px 0px #c5f1c0;
  outline: none;
  color: #333;
  width: 1058px;
  font-size: 14px;
  min-height: 150px;
  line-height: 32px;
}

.breadcrumb-preview .el-breadcrumb ::v-deep .el-breadcrumb__separator {
  margin: 0 9px;
  color: #fff;
  font-weight: 500;
}

.breadcrumb-preview .el-breadcrumb ::v-deep .el-breadcrumb__inner a {
  color: #fff;
  display: inline-block;
}

.breadcrumb-preview .el-breadcrumb ::v-deep .el-breadcrumb__inner {
  color: #fff;
  display: inline-block;
}

.el-pagination ::v-deep .el-pagination__total {
  margin: 0 10px 0 0;
  color: #666;
  font-weight: 400;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .btn-prev {
  border: none;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #666;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  min-width: 35px;
  height: 28px;
}

.el-pagination ::v-deep .btn-next {
  border: none;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #666;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  min-width: 35px;
  height: 28px;
}

.el-pagination ::v-deep .btn-prev:disabled {
  border: none;
  cursor: not-allowed;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #C0C4CC;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .btn-next:disabled {
  border: none;
  cursor: not-allowed;
  border-radius: 2px;
  padding: 0;
  margin: 0 5px;
  color: #C0C4CC;
  background: #f4f4f5;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager {
  padding: 0;
  margin: 0;
  display: inline-block;
  vertical-align: top;
}

.el-pagination ::v-deep .el-pager .number {
  cursor: pointer;
  padding: 0 4px;
  margin: 0 5px;
  color: #666;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #f4f4f5;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager .number:hover {
  cursor: pointer;
  padding: 0 4px;
  margin: 0 5px;
  color: #ff9966;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #f4f4f5;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pager .number.active {
  cursor: default;
  padding: 0 4px;
  margin: 0 5px;
  color: #FFF;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  border-radius: 2px;
  background: #ff9966;
  text-align: center;
  min-width: 30px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes {
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input {
  margin: 0 5px;
  width: 100px;
  position: relative;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input .el-input__inner {
  border: 1px solid #DCDFE6;
  cursor: pointer;
  padding: 0 25px 0 8px;
  color: #606266;
  display: inline-block;
  font-size: 13px;
  line-height: 28px;
  border-radius: 3px;
  outline: 0;
  background: #FFF;
  width: 100%;
  text-align: center;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input span.el-input__suffix {
  top: 0;
  position: absolute;
  right: 0;
  height: 100%;
}

.el-pagination ::v-deep .el-pagination__sizes .el-input .el-input__suffix .el-select__caret {
  cursor: pointer;
  color: #C0C4CC;
  width: 25px;
  font-size: 14px;
  line-height: 28px;
  text-align: center;
}

.el-pagination ::v-deep .el-pagination__jump {
  margin: 0 0 0 24px;
  color: #606266;
  display: inline-block;
  vertical-align: top;
  font-size: 13px;
  line-height: 28px;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__jump .el-input {
  border-radius: 3px;
  padding: 0 2px;
  margin: 0 2px;
  display: inline-block;
  width: 50px;
  font-size: 14px;
  line-height: 18px;
  position: relative;
  text-align: center;
  height: 28px;
}

.el-pagination ::v-deep .el-pagination__jump .el-input .el-input__inner {
  border: 1px solid #DCDFE6;
  cursor: pointer;
  padding: 0 3px;
  color: #606266;
  display: inline-block;
  font-size: 14px;
  line-height: 28px;
  border-radius: 3px;
  outline: 0;
  background: #FFF;
  width: 100%;
  text-align: center;
  height: 28px;
}
</style>
